package club.janna.trace.web;

import club.janna.trace.api.AService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;

/**
 * @author Panbo.Guo
 */
@Slf4j
@RestController
@ControllerAdvice
@SpringBootApplication
public class Bootstrap {

    @DubboReference
    private AService aService;

    public static void main(String[] args) {
        SpringApplication.run(Bootstrap.class, args);
    }

    @GetMapping("/")
    public String hello() {
        return "Hello, World!";
    }

    @GetMapping("/get/{id}")
    public String getValue(@PathVariable("id") Long id) {
        return aService.getValue(id);
    }

    /**
     * 处理异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public String exceptionHandler(Exception e) {
        log.error("发生异常！", e);
        return e.getMessage();
    }
}

